import * as native_tools from "../system/native_tools";
import * as math_tools from "../system/math_tools";
const defaultTag = 'data_tag:magic_tool.series';
;
function DestroyComponentTrigger(source) {
    const state = source.destroyedBlockPermutation;
    const dimension = source.dimension;
    const player = source.player;
    const block = source.block;
    const item = player?.getComponent('minecraft:inventory')?.container?.getItem(player.selectedSlotIndex);
    return { state, dimension, player, block, item };
}
;
export function CrystalTankTrigger() {
    return {
        onPlayerDestroy(source) {
            const analysis = DestroyComponentTrigger(source);
            if (!analysis.item?.hasTag(defaultTag))
                return;
            const anchor = math_tools.Vector.toString(analysis.block.above()?.bottomCenter(), { delimiter: ' ' });
            analysis.dimension.runCommand(`loot spawn ${anchor} loot "energy_crystal/random"`);
            analysis.block.dimension?.playSound('cauldron.explode', analysis.block.location);
            switch (math_tools.Random({ max: 4, min: 0 }, true)) {
                case 0:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_red', analysis.block.above()?.bottomCenter());
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_paper_rune_red', analysis.block.above()?.bottomCenter());
                    break;
                case 1:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_blue', analysis.block.above()?.bottomCenter());
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_paper_rune_blue', analysis.block.above()?.bottomCenter());
                    break;
                case 2:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_green', analysis.block.above()?.bottomCenter());
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_paper_rune_green', analysis.block.above()?.bottomCenter());
                    break;
                case 3:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_orange', analysis.block.above()?.bottomCenter());
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_paper_rune_orange', analysis.block.above()?.bottomCenter());
                    break;
                case 4:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_purple', analysis.block.above()?.bottomCenter());
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_paper_rune_purple', analysis.block.above()?.bottomCenter());
                    break;
                default: break;
            }
        }
    };
}
